const Cache = require('./Cache')

const Setting = new Cache('setting')
module.exports = function (groupId) {
    return {
        async set(key, value) {
            const item = await Setting.upsert({
                key,
                groupId
            },
			{
			    key,
			    value,
			    groupId
			})
            return item.value
        },
        async get(key, defaultValue) {
            const item = await Setting.findOne({
                key,
                groupId
            })
            return item?.value ?? defaultValue
        },
        async del(key) {
            const item = await Setting.remove({
                key,
                groupId
            })
            return item?.value
        }
    }
}
